package I;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 取款界面
 */
public class GetPanel extends JPanel implements ActionListener {
    private ATMFrame atmFrame;
    private ImageIcon lginImg = new ImageIcon("picture/buttonSure.jpg");
    private JLabel money = new JLabel("取款金额：");
    private JTextField sumOfMonry = new JTextField();
    private Font font = new Font("黑体",Font.BOLD,20);
    private JButton loginBtn = new JButton(lginImg);
    public GetPanel(ATMFrame atmFrame){
        this.atmFrame = atmFrame;
        this.setLayout(null);
        money.setBounds(300,250,120,50);
        money.setFont(font);
        sumOfMonry.setBounds(400,250,250,50);
        sumOfMonry.setFont(font);
        loginBtn.setBounds(400,350,140,50);
        loginBtn.addActionListener(this);
        this.add(money);
        this.add(sumOfMonry);
        this.add(loginBtn);
        this.setOpaque(false);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == loginBtn){
            User user = atmFrame.getLoginUser();
            try {
                user.setBlance(user.getBlance()-Double.parseDouble(sumOfMonry.getText()));
            }catch (NumberFormatException a){
                JOptionPane.showMessageDialog(this,"请输入数字");
            }
            atmFrame.switchPanel("menu");
        }
    }
}
